<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Admins extends Model
{
    // 用户表
    protected $table = 'admins';
    protected $primaryKey = 'id';
    protected $dateFormat = 'U';
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i',
        'updated_at' => 'datetime:Y-m-d H:i'
    ];

    public function login($data){
        $user = $this::where('account',$data['account'])->first();
        if (!$user){
            return ['code' => 3000,'success' => false, 'msg' => '用户不存在','user' => $user];
        }
        if (Md5Pass($user->safe_key,$data['password']) !== $user->password){
            return ['code' => 3002, 'success' => false, 'msg' => '密码错误', 'user' => [Md5Pass($user->safe_key,$data['password']), $user->password]];
        }else{
            return ['code' => 200, 'success' => true, 'msg' => '登录成功','user' => $user];
        }
    }
}
